<template>
    <div>
        <InputText inputName="邮箱" @username = "getusername" contentType="email"></InputText>
        <InputText inputName="密码" @password = "getpassword" contentType="pwd"></InputText>
        <button class="btn btn-block btn-primary" @click="getuserinfo">登录</button>
        <p>用户名：{{ username }}</p>
        <p>密码：{{ password }}</p>
    </div>
</template>

<script>
    import InputText from '../common/InputText'
    import axios from 'axios'
    export default {
        data(){
            return{
                username:'',
                password:'',
                userinfo:{}
            }
        },
        components:{
            InputText
        },
        methods:{
            getusername: function(username){
                this.username = username
            },
            getpassword: function(password){
                this.password = password
            },
            getuserinfo: function(){
                axios.get('/api/userinfo.json',{
                    params:{
                        username:this.username,
                        password:this.password
                    }
                })
                .then(this.getUserInfoSucc)
            },
            getUserInfoSucc(res){
                res = res.data
                if(res.ret && res.login && res.userinfo){
                    var data = res.userinfo
                    this.userinfo = data.userinfo
                    console.log(data)
                    document.cookie="id=" + data.id + "username=" + data.name
                    console.log(document.cookie)
                    this.$router.push('Service')
                }else{
                    console.log('账号或密码错误!')
                    this.$router.push('Login')
                }
            }
        }
    }
</script>

<style scoped>
    
</style>